package com.forsir.android.mhfinance.storeObjects;

import android.content.ContentValues;
import android.database.Cursor;

import com.forsir.android.mhfinance.helper.DbAdapter;

public class Account extends IStorable {
	private String name;

	// only for report
	public float summaryWithdraw = 0;
	public float summaryDeposit = 0;
	public int count = 0;

	public Account() {
	}

	public Account(long accountId) {
		setId(accountId);
	}

	public Account(Cursor cursor) {
		fillFromCursor(cursor);
	}

	public void cleanSummary() {
		summaryWithdraw = 0;
		summaryDeposit = 0;
		count = 0;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public ContentValues getContent() {
		final ContentValues content = new ContentValues();
		content.put(DbAdapter.ACCOUNT_NAME, getName());
		return content;
	}

	@Override
	public String getTableName() {
		return DbAdapter.ACCOUNT_TABLE;
	}

	@Override
	public String[] getColumns() {
		return new String[] { DbAdapter.ID, DbAdapter.ACCOUNT_NAME };
	}

	@Override
	/*
	 * * gets values from actual position of cursor
	 */
	public IStorable fillFromCursor(Cursor cursor) {
		if (cursor == null) {
			setId(-1);
			name = "";
			return this;
		}

		if (!cursor.isAfterLast()) {
			setId(cursor.getLong(cursor.getColumnIndex(DbAdapter.ID)));
			name = cursor.getString(cursor.getColumnIndex(DbAdapter.ACCOUNT_NAME));
		}

		return this;
	}
}
